package com.da.javatest.leetCode;

import java.util.HashSet;
import java.util.Set;

/**
 * @author chenlida
 * @date 2019/1/14 17:37
 * @description
 */
public class Code965 {
    private Set<Integer> s = new HashSet<>();

    public boolean isUnivalTree(TreeNode root) {
        setSet(root);
        return s.size() == 1;
    }

    private void setSet(TreeNode node) {
        if (node != null) {
            s.add(node.val);
            setSet(node.left);
            setSet(node.right);
        }
    }
}
